package com.ygqh.baby.controller.admin;

import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.model.MediaDownloadResult;
import com.foxinmy.weixin4j.model.MediaUploadResult;
import com.ygqh.baby.ao.Message;
import com.ygqh.baby.service.WeixinMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 〈微信素材〉
 *
 * @author guohao
 * @date 2019/1/11 12:43
 * @since 1.0.0
 */
@RequestMapping("/admin/weixinMaterial")
@Controller
public class WeixinMaterialController {

    @Autowired
    private WeixinMaterialService weixinMaterialService;


    @RequestMapping("addImageMaterial")
    @ResponseBody
    public Message addImageMaterial(String url, boolean forever, String fileName) throws WeixinException {
        MediaUploadResult mediaUploadResult = weixinMaterialService.addImageMaterial(forever, url, fileName);
        return Message.success(mediaUploadResult);
    }

    @RequestMapping("downloadMedia")
    @ResponseBody
        public Message downloadMedia(String mediaId, boolean forever) throws WeixinException {
        MediaDownloadResult mediaDownloadResult = weixinMaterialService.downloadMedia(mediaId, forever);
        return Message.success(mediaDownloadResult);
    }
}
